package com.galaxy.maven.tools.autoconfig;

public class StringUtil {

    public static String replaceStr(String source, String oldString, String newString) {

        StringBuffer output = new StringBuffer();
        int lengthOfSource = source.length(); // source string length
        int lengthOfOld = oldString.length(); // old string length
        int posStart = 0; // start search index
        int pos; // the position old string has bean search
        while ((pos = source.indexOf(oldString, posStart)) >= 0) {
            output.append(source.substring(posStart, pos));
            output.append(newString);
            posStart = pos + lengthOfOld;
        }
        if (posStart < lengthOfSource) {
            output.append(source.substring(posStart));
        }
        return output.toString();
    }
}
